{ INFORMATICS.MCCME.RU
  Problem statement: http://informatics.mccme.ru/moodle/mod/statements/view3.php?chapterid=26
  Verdict: Accepted
}
var
   i,n,q,c,d,e,cp:longint;
   a,b:array[0..30] of longint;
   rp,rt:int64;
   t:array[0..30,1..4] of int64;
 
begin
assign(input,'input.txt');
assign(output,'output.txt');
reset(input);
rewrite(output);
read(n);
fillchar(t,sizeof(t),0);
for i:=1 to n do read(a[i]);
for i:=1 to n do read(b[i]);
read(q);
rp:=0;
rt:=0;
for i:=1 to q do begin
    read(c,d,e);
    if e<>-1 then begin
       inc(t[d][3]);
       if e>=a[d] then cp:=2 else
       if e>=b[d] then cp:=1 else cp:=0;
       if cp>t[d][1] then begin
          t[d][1]:=cp;
          t[d][2]:=t[d][3];
          t[d][4]:=c;
       end;
    end;
end;
for i:=1 to n do
    if t[i][1]>0 then begin
       inc(rp,t[i][1]);
       inc(rt,(t[i][2]-1)*20+t[i][4]);
    end;
write(rp,' ',rt);
end
